package com.hsd.ha.app.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hsd.core.base.dao.impl.BaseDAO;
import com.hsd.core.utils.PageParam;
import com.hsd.core.utils.PageQuery;
import com.hsd.core.utils.PageUtil;
import com.hsd.ha.app.dao.IHealthAssessmentDao;

@Repository 
public class HealthAssessmentDaoImpl extends BaseDAO implements IHealthAssessmentDao{
	@Override
	public PageUtil loadMySurveyList(PageParam pageParam) {
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("surveyName"))
		{     
			query.setString(i++, "%"+(String)map.get("surveyName")+"%");
		}  
		PageUtil pu = pq.getPageUtil(query,this.getSession());
		return pu;
	}

	@Override
	public List loadHpList(Long id) { 
 		StringBuffer buffer = new StringBuffer();
		buffer.append("select c.* from hsd_hp_info c,(select a.rid from hsd_dss_relation  a,hsd_dssinfo b where a.dssid=b.id and a.rtype=1 and  b.id=?) d where c.id=d.rid");
		List datalist = this.jdbcTemplate.queryForList(buffer.toString(),new Object[]{id}); 
		return datalist;
	}

	@Override
	public List loadHpList(String codestr) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("select c.* from hsd_hp_info c,(select a.rid from hsd_dss_relation  a,hsd_dssinfo b where a.dssid=b.id and a.rtype=1 and  b.codestr=?) d where c.id=d.rid");
		List datalist = this.jdbcTemplate.queryForList(buffer.toString(),new Object[]{codestr}); 
		return datalist;
	}
	 
 
}
